//
//  MDMusementCell.swift
//  麦兜直播
//
//  Created by Apple on 16/10/21.
//  Copyright © 2016年 yeqingyu. All rights reserved.
//

import UIKit
private let museUnitCell = "museUnitCellID"



class MDMusementCell: UICollectionViewCell {
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var layout: UICollectionViewFlowLayout!
   
    var datas:[MDHomeGroup]?{
        didSet{
          collectionView.reloadData()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        collectionView.register(UINib(nibName: "MDGameCell", bundle: nil), forCellWithReuseIdentifier: museUnitCell)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let itemH = collectionView.bounds.size.height/2.0
        let itemW = collectionView.bounds.size.width/4.0
        layout.itemSize = CGSize(width: itemW, height: itemH)
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        
    }
}


// MARK:- 数据源方法
extension MDMusementCell:UICollectionViewDataSource{
    
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return datas!.count 
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: museUnitCell, for: indexPath) as! MDGameCell
        cell.homeGroup = datas?[indexPath.row]
        cell.line.isHidden = true
        return cell
    }
}
